// PARADIME INTERPRETER
//
//LICENSED FREELY UNDER MIT.

/*
ARRAY CODE taken from AutoIT

	void ArrayDetailsCreate(void);
	int ArrayGetElemIndex(int* subs);
	int DeclareAsArray(int* subs);
	Variant* ArrayGetRef(int* subs, bool bCreate);

Copyright 2006 Jonathon Bennett and the AutoIT Authors

http://www.autoitscript.com/autoit3/docs/credits.htm

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/




#ifndef EXPLOR_VARIANT
#define EXPLOR_VARIANT

#include "limits.h"

// Define the types of variants that we allow
#define VAR_ERROR			0					// Invalid comparision type
#define VAR_INT32			1					// 32bit Integer
#define VAR_INT64			2					// 64bit Integer
#define VAR_DOUBLE			3					// Double float
#define VAR_STRING			4					// String
#define VAR_ARRAY			5					// Array of variants
#define VAR_REFERENCE		6					// Reference to another variant
#define VAR_HWND			7					// Handle (Window)

class Variant
{
public:

	Variant(int mode);
	Variant();

	int GetInt32();
	__int64 GetInt64();
	double GetDouble();
	char* GetString();

	void SetInt32(int);
	void SetInt64(__int64);
	void SetDouble(double);
	void SetString(char*);
	void SetFromToken(void* token);

	int DeclareAsArray(int* subs);
	Variant* ArrayGetRef(int* subs, bool bCreate);

	void StorageReset(void);

	int IsTrue(void);


	// Structure used for storing array details
	//Credits to Jon from the AutoIT project. Array code used under provided license.
	typedef struct
	{
		Variant	**Data;							// Memory area for the array (array of Variant pointers) (NULL = not used)

		int		nElements;						// Actual number of elements in array ([10][10] = 100 elements)
		int		Subscript[VAR_SUBSCRIPT_MAX];	// Subscript details
		int		SubscriptCur[VAR_SUBSCRIPT_MAX];	// Current subscript
		char	Dimensions;						// Number of dimensions/subscripts
		char	DimensionsCur;					// Current number of dimensions

	} VariantArrayDetails;


	// Single variant variables
	//Credits to Jon from the AutoIT project. Array code used under provided license.
	union
	{
		int					m_nValue;			// Value of int32 (for VAR_INT32)
		__int64				m_n64Value;			// Value of int64 (for VAR_INT64)
		double				m_fValue;			// Value of double (for VAR_DOUBLE)
		Variant				*m_pValue;			// Value of pointer (for VAR_REFERENCE)
		VariantArrayDetails	*m_Array;			// Value of array (for VAR_ARRAY)
		HWND				m_hWnd;				// Value of handle (for VAR_HWND)
	};


	//Always a string available, even if not a string type.
	char		*StrRep;						// Value of string (NULL = not avail)
	int			AllocatedBytes;					// Amount of bytes allocated for the above string

	int			VarType;						// Type of this variant
private:
	void ArrayDeAllocate(void);
	void ArrayDetailsCreate(void);
	int ArrayGetElemIndex(int* subs);
};

void VariantConversionTest(void);

#endif

